

<?php $__env->startSection('content'); ?>
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <div class="layui-btn-group">
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage.create')): ?>
                    <a class="layui-btn layui-btn-sm" href="<?php echo e(route('admin.logistics.create')); ?>">添 加</a>
                <?php endif; ?>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage.destroy')): ?>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" id="listDelete">批量删除</button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" id="truncateBtn">一键清空</button>
                <?php endif; ?>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage.import')): ?>
                    <a class="layui-btn layui-btn-sm" id="importBtn">导 入</a>
                <?php endif; ?>
                    <a class="layui-btn layui-btn-sm" id="searchBtn">搜 索</a>
            </div>
            <div class="layui-form" >
                <div class="layui-input-inline">
                    <input type="text" name="order_num" id="order_num" placeholder="请输入运单号" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="accept_phone" id="accept_phone" placeholder="请输入收件人手机号" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage.edit')): ?>
                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                    <?php endif; ?>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage.destroy')): ?>
                        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
                    <?php endif; ?>
                </div>
            </script>
        </div>
    </div>

    <!-- 导入数据html -->
    <script type="text/html" id="importHtml">
        <div class="layui-form" style="padding:10px 20px">
            <div class="layui-form-item">
                <label for="" class="layui-form-label">上传文件</label>
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-sm" id="uploadBtn" >选择文件</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label"></label>
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-sm" id="submitBtn" >确认导入</button>
                    <a class="layui-btn layui-btn-sm" href="/template.xlsx" id="tempFile" target="_blank" >模板下载</a>
                </div>
            </div>
        </div>
    </script>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('logistics.manage')): ?>
        <script>
            layui.use(['layer','table','form','upload'],function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                var upload = layui.upload;
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    ,height: 500
                    ,url: "<?php echo e(route('admin.logistics.data')); ?>" //数据接口
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {checkbox: true,fixed: true}
                        ,{field: 'id', title: 'ID', sort: true,width:80}
                        ,{field: 'sent_at', title: '发件时间'}
                        ,{field: 'company_name', title: '快递公司'}
                        ,{field: 'order_num', title: '运单号'}
                        ,{field: 'goods_type', title: '物品类型'}
                        ,{field: 'accept_name', title: '收件人姓名'}
                        ,{field: 'accept_phone', title: '收件人手机'}
                        ,{fixed: 'right', width: 220, align:'center', toolbar: '#options'}
                    ]]
                });

                //监听工具条
                table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent === 'del'){
                        layer.confirm('确认删除吗？', function(index){
                            $.post("<?php echo e(route('admin.logistics.destroy')); ?>",{_method:'delete',ids:[data.id]},function (result) {
                                if (result.code==0){
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg)
                            });
                        });
                    } else if(layEvent === 'edit'){
                        location.href = '/admin/logistics/'+data.id+'/edit';
                    }
                });
                //导入
                $("#importBtn").click(function () {
                    layer.open({
                        title:'导入数据',
                        type:1,
                        area:'400px',
                        content:$("#importHtml").html()
                    });
                    $("#tempFile").mouseover(function () {
                        layer.tips("模板文件结构请勿随意修改",$(this),{tips:1})
                    })
                    //执行实例
                    var uploadInst = upload.render({
                        elem: '#uploadBtn' //绑定元素
                        ,url: "<?php echo e(route('admin.logistics.import')); ?>" //上传接口
                        ,auto:false
                        ,bindAction:'#submitBtn'
                        ,accept:'file'
                        ,exts:'xlsx'
                        ,done: function(res){
                            layer.msg(res.msg,{time:2000},function () {
                                if (res.code==0){
                                    layer.closeAll();
                                    dataTable.reload({
                                        where: {curr:1}
                                    })
                                }
                            })
                        }
                        ,error: function(){
                            layer.msg("请求异常")
                        }
                    });
                })
                //搜索
                $("#searchBtn").click(function(){
                    var order_num=$("#order_num").val();
                    var accept_phone=$("#accept_phone").val();
                    if(order_num==''&&accept_phone==''){
                        return layer.msg('请至少输入一个搜索条件');
                    }
                    dataTable.reload({
                        where:{curr:1,'order_num':order_num,'accept_phone':accept_phone}
                    })
                })
                //按钮批量删除
                $("#listDelete").click(function () {
                    var ids = []
                    var hasCheck = table.checkStatus('dataTable')
                    var hasCheckData = hasCheck.data
                    if (hasCheckData.length>0){
                        $.each(hasCheckData,function (index,element) {
                            ids.push(element.id)
                        })
                    }
                    if (ids.length>0){
                        layer.confirm('确认删除吗？', function(index){
                            $.post("<?php echo e(route('admin.logistics.destroy')); ?>",{_method:'delete',ids:ids},function (result) {
                                if (result.code==0){
                                    dataTable.reload({page:{curr:1}})
                                }
                                layer.close(index);
                                layer.msg(result.msg)
                            });
                        })
                    }else {
                        layer.msg('请选择删除项')
                    }
                })
                //truncateBtn
                $("#truncateBtn").click(function(){
                    layer.confirm('此操作将删除所有数据，确认清空吗？',function () {
                        $.get("<?php echo e(route('admin.logistics.truncate')); ?>",function (res) {
                            layer.msg(res.msg,{time:1500},function () {
                                dataTable.reload({
                                    page:{curr:1}
                                })
                            })
                        })
                    })
                })
            })
        </script>
    <?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.base', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>